﻿// Decompiled with JetBrains decompiler
// Type: Netick.Unity.PhysicsSimulationStep
// Assembly: Netick.Unity, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E128C7FD-39ED-4452-86AC-6EC748457030
// Assembly location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.Unity.dll
// XML documentation location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.Unity.xml

#nullable disable
namespace Netick.Unity;

/// <summary>
/// Executes the physics (PhysX or Box2D) simulation step during the <c>NetworkFixedUpdate</c> callback of Netick.
/// </summary>
[ExecutionOrder(1000)]
public class PhysicsSimulationStep : NetickCoreComponent
{
  internal PhysicsSimulationStep()
  {
  }

  public override void NetworkFixedUpdate()
  {
    if (!this.Sandbox.HasLoadScene || !this.Sandbox.PhysicsPrediction && this.Engine.IsResimulating || this.Sandbox.Config.PhysicsType == PhysicsType.None)
      return;
    if (this.Sandbox.Config.PhysicsType == PhysicsType.Physics2D)
      this.Sandbox.Physics2D.Simulate(this.Sandbox.ScaledFixedDeltaTime);
    else if (this.Sandbox.Config.PhysicsType == PhysicsType.Physics3D)
      this.Sandbox.Physics.Simulate(this.Sandbox.ScaledFixedDeltaTime);
    if (this.Engine.IsResimulating)
      return;
    this.PostSimulation();
  }

  public void PostSimulation() => this.Sandbox.LocalRigidbodyFixer.PostSimulation();
}
